package com.yehuishou.service.impl;

import java.util.ArrayList;
import java.util.FormatFlagsConversionMismatchException;
import java.util.List;

import javax.annotation.Resource;
import org.springframework.stereotype.Service;

import com.yehuishou.dao.AssessmentValueDao;
import com.yehuishou.dao.BackAssessmentDao;
import com.yehuishou.dao.BackItemDao;
import com.yehuishou.pojo.AssessmentValue;
import com.yehuishou.pojo.BackAssessment;
import com.yehuishou.pojo.BackItem;
import com.yehuishou.service.BackAssessmentService;


@Service
public class BackAssessmentServiceImpl implements BackAssessmentService {
    
	@Resource
	private BackAssessmentDao backAssessmentDao;
	
	@Resource
	private AssessmentValueDao  AssessmentValueDao;
	
	@Resource
	private BackItemDao backItemDao;
	
	@Override
	public List<BackAssessment> getBackAssessment(Integer cid) {
		// TODO Auto-generated method stub
		return backAssessmentDao.getBackAssessment(cid);
	}

	@Override
	public void insertBackAssessment(BackAssessment back) {
		// TODO Auto-generated method stub
		backAssessmentDao.insertBackAssessment(back);
	}

	@Override
	public boolean checkAssessExist(BackAssessment back) {
		
		boolean flag =false;
		if((backAssessmentDao.checkAssessExist(back))!=null) {
			
	       flag = true;
		}
		
		return flag;
	}

	@Override
	public List<BackAssessment> selectBackAssessment(Integer id) {
		
		List<BackAssessment> assess = new ArrayList<>();
		//根据id获取cid
		BackItem backItem =backItemDao.getBackItemById(id);
		AssessmentValue  as = new AssessmentValue();
		as.setBack_id(id);
		//获取商品对应属性的集合
		List<BackAssessment> back = backAssessmentDao.getBackAssessment(backItem.getCid());
        
		for(int i=0;i<back.size();i++) {
			BackAssessment bs  = new BackAssessment();
			bs.setAssessname(back.get(i).getAssessname());
			as.setAssess_id(back.get(i).getAssess_id());
			bs.setAssess_id(back.get(i).getAssess_id());
		List<AssessmentValue> assessment =AssessmentValueDao.getAssessmentValueByid(as);	
		if(assessment.size()>0) {
		bs.setAssessmentValues(assessment);
		 assess.add(bs);
		}
		
		}
		return assess;
	}

}
